<template>
	<view class="login-container">
		<!---->
		<u-toast ref="uToast"/>
		<!---->
		<div class="top-container">
			<div class="top-title">
				您好，<br />欢迎使用
			</div>
		</div>
		<!---->
		<div class="content-container">
			<view class="login-content">
				<view>
					<text class="label">手机号</text>
					<input type="number" name="phone" placeholder="请输入您的手机号" maxlength="11" v-model="username" />
				</view>
				<view>
					<text class="label">密码</text>
					<input type="password" name="code" maxlength="18" placeholder="请输入您的密码" v-model="password" />
				</view>
				<button @tap="login()">登 录</button>
				<view class="text-message" @tap="">短信登录</view>
			</view>

			<!-- #ifdef MP-WEIXIN -->
			<view class="wxlogin-container">
				<button open-type="getPhoneNumber" @getphonenumber="weChatLogin" class="clearBtn">
					<view class="loginType">
						<view class="item">
							<view class="icon">
								<u-icon size="60" name="weixin-fill" color="rgb(83,194,64)"/>
							</view>
							微信
						</view>
					</view>
				</button>
			</view>
			<!-- #endif -->
		</div>
	</view>
</template>

<script>
export default {
	data() {
		return {
            username: '',
            password: '',

		}
	},
	created() {

	},
	methods: {
	    login(){
	        let _ = this
	        //校验
            if(!this.$u.test.mobile(this.username)){
                return uni.$u.toast('手机号不正确')
            }
            if(!this.password){
                return uni.$u.toast('密码不能为空')
            }
		},
        weChatLogin(e){
	        console.log('weChatLogin')
            let code= e.detail.code;
            if(code){
                uni.showLoading({title:"登录中....",mask:true})
                // let url = "/api/miniWxApi/getPhoneNum?code="+code;
                // this.$u.get(url).then(res => {
                //     let phoneNum = res.phoneNum
                //     let weChatUrl = "/api/weChatLogin";
                //     this.$u.post(weChatUrl,{
                //         username: phoneNum,
                //         code: code
                //     }).then(data => {
                //         uni.hideLoading();
                //         // 登录成功初始化token与用户信息
                //         this.$u.vuex('vuex_token', data.token);
                //         this.$u.vuex('vuex_user', data.loginUser);
                //         uni.switchTab({
                //             url: '/pages/index/index'
                //         })
                //     });
                // });
            }else{
                // this.$mytip.toast('登录失败')
            }
		}
	}
}
</script>
<style lang="scss" scoped>
@import 'index.scss';
</style>
